﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TrinityEngine.UI
{
    public class Image : Renderer
    {
        public Texture2D texture;

        public bool flipX;

        public bool flipY;

        private Rectangle _rect;

        public Image(Texture2D texture)
        {
            this.texture = texture;
            flipX = false;
            flipY = false;
        }

        protected override void Update()
        {
            base.Update();
            /*pivot = (transform as RectTransform).pivot;*/
/*            _rect.Location = _position.RoundToInt();
            _rect.Size = (_scale * (transform as RectTransform).sizeDelta).RoundToInt();*/
            /*_origin = new Vector2(texture.Width * pivot.x, texture.Height * pivot.y);*/
        }

        protected override void Render()
        {
            if (texture == null)
            {
                return;
            }

            SpriteEffects effects = SpriteEffects.None;
            float flipRotation = 0f;
            if (flipX && !flipY)
            {
                effects = SpriteEffects.FlipHorizontally;
            }
            else if (flipY && !flipX)
            {
                effects = SpriteEffects.FlipVertically;
            }
            else if (flipX && flipY)
            {
                flipRotation = 180f;
            }

            /*Engine.Instance.batch.Draw(
                texture,
                _rect,
                null,
                tint,
                (_rotation + flipRotation) * Mathf.Deg2Rad,
                _origin,
                effects,
                sortingLayer);*/
        }

        protected override void OnDestroy()
        {
            texture = null;
        }
    }
}
